package com.example.copy;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.os.Bundle;
import android.widget.ImageView;

/**
 * 创建副本对象
 */
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //原图
        ImageView iv_src = (ImageView) findViewById(R.id.iv_src);
        //副本
        ImageView iv_copy = (ImageView) findViewById(R.id.iv_copy);

        //原图 不可更改
        Bitmap srcBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.bg);
        iv_src.setImageBitmap(srcBitmap);

        //模板 (副本)
        Bitmap copyBitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), srcBitmap.getConfig());

        //创建画布
        Canvas canvas = new Canvas(copyBitmap);

        //创建画笔
        Paint paint = new Paint();

        //开始画画   矩阵
        canvas.drawBitmap(srcBitmap,new Matrix(),paint);

        for (int i = 0 ; i < 100 ;i++){
            for (int j = 0 ; j < 100;j++){
                copyBitmap.setPixel(100+i,100+j, Color.BLACK);
            }
        }
        iv_copy.setImageBitmap(copyBitmap);
    }
}
